
jQuery(document).ready(function( ) {
// 特卖倒计时
	var parent=$('#counter1');
	var day=parent.find('.t0');
	var hour=parent.find('.t1');
	var min=parent.find('.t2');
	var sec=parent.find('.t3');
	var msec=parent.find('.t4');

	var dayt=parent.find('.t0').text();
	var hourt=parent.find('.t1').text();
	var mint=parent.find('.t2').text();
	var sect=parent.find('.t3').text();
	var msect=parent.find('.t4').text();
	
	var addday=setInterval(add0,24*3600000);
	var addhour=setInterval(add1,3600000);
	var addmin=setInterval(add2,60000);
	var addsec=setInterval(add3,1000);
	var addmsec=setInterval(add4,100);


	function add4(){
		if(dayt!=0 || hourt!=0 || mint!=0 || sect!=0||msect!=0)
			{
				if(msect==0){
					msec.text(10);
					msect=10;
				}
				else{
					msec.text(msect-1);
					msect-=1;
				}
			}
		else {
			clearInterval(addmsec);
			$('.SoldOut').removeClass('hidden');
		}
	}
	function add3(){
		if(dayt!=0 || hourt!=0 || mint!=0 ||sect!=0)
			{
				if(sect==0){
					sec.text(60);
					sect=60;
				}
				else{
					sec.text(sect-1);
					sect-=1;
				}
			}
		else {
			clearInterval(addsec);
		}
	}
	function add2(){
		if(dayt!=0 || hourt!=0 ||mint!=0 )
			{
				if(mint==0){
					min.text(60);
					mint=60;
				}
				else{
					min.text(mint-1);
					mint-=1;
				}
			}
		else {
			clearInterval(addmin);
		}
	}
	function add1(){
		if(dayt!=0||hourt!=0 )
			{
				if(hourt==0){
					hour.text(24);
					hourt=24;
				}
				else{
					hour.text(hourt-1);
					hourt-=1;
				}
			}
		else {
			clearInterval(addhour);
		}
	}
	function add0(){
		if(dayt<=0){
			clearInterval(addday);
		}
		else{
			day.text(dayt-1);
			dayt-=1;
		}
	}


	// 健康测评-问题页
	$('.question-answer i').click(function( ) {
		$(this).find('input').attr('checked','checked');
		$(this).parent().addClass('on').siblings('p').removeClass('on').find('input').removeAttr('checked');
	});
	var myparent=$('.question-list');
	var mylength=myparent.find('li').length;
	var nowQuestion,nextQuestion,prevQuestion;
	nowQuestion=myparent.find('li.on').index();
	$(".question-control .percent").text(((nowQuestion+1)*100/mylength).toFixed(0) + '%');
			$(".question-control .percent").css({left:((nowQuestion+1)*100/mylength).toFixed(0)+'%'});
			$(".question-control .bar").css({width:((nowQuestion+1)*100/mylength).toFixed(0)+'%'});
	// 下一题
	$('.question-control .next').click(function( ) {
		nowQuestion=myparent.find('li.on').index();
		nextQuestion=nowQuestion+1;
		if(myparent.find('li').eq(nowQuestion).find('.question-answer p.on').length==0){
			alert('请答题！');
			return;
		}
//		else{
			if(nextQuestion<mylength){
				myparent.find('li').eq(nextQuestion).addClass('on').siblings('li').removeClass('on');
				$(".question-control .percent").text(((nextQuestion+1)*100/mylength).toFixed(0) + '%');
				$(".question-control .percent").css({left:((nextQuestion+1)*100/mylength).toFixed(0)+'%'});
				$(".question-control .bar").css({width:((nextQuestion+1)*100/mylength).toFixed(0)+'%'});
				if(nextQuestion==mylength-1){
					$(this).css('display','none').siblings('.submit').css('display','block');
				}
				$(".question-num i").eq(nextQuestion).addClass("in");
				$(".question-num .on").text(nextQuestion+1);
			}
//		}	
	});
	// 上一题
	$('.question-control .prev').click(function( ) {
		nowQuestion=myparent.find('li.on').index();
		prevQuestion=nowQuestion-1;
		if(prevQuestion>=0){
			myparent.find('li').eq(prevQuestion).addClass('on').siblings('li').removeClass('on');
			$(".question-control .percent").text(((nowQuestion)*100/mylength).toFixed(0) + '%');
			$(".question-control .percent").css({left:((nowQuestion)*100/mylength).toFixed(0)+'%'});
			$(".question-control .bar").css({width:((nowQuestion)*100/mylength).toFixed(0)+'%'});
			if(nowQuestion<=mylength){
				$(this).siblings('.submit').css('display','none').siblings('.next').css('display','block');
			}
			$(".question-num i").eq(nowQuestion).removeClass("in");
			$(".question-num .on").text(nowQuestion);
		}
	});
	// 提交
	$('.question-control .submit').click(function() {
		nowQuestion=myparent.find('li.on').index();
		nextQuestion=nowQuestion+1;
		if(myparent.find('li').eq(nowQuestion).find('.question-answer p.on').length==0){
			alert('请答题！');
		}
		else{
			document.getElementById('theForm').submit();
		}
	});

	$('.p-list .list-all li').hover(function() {
		$(this).addClass('curr');
	}, function() {
		$(this).removeClass('curr');
	});
});